package com.zzh.jetpackdemo.paging

import android.R
import android.os.Parcel
import android.os.Parcelable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.NonNull
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.RecyclerView
import java.lang.String


/**
 * @author zhangzhihao
 * @email zhangzhihao@gongjiangren.net
 * @date 2020-11-25
 * @desc
 */
open class CalendarAdapter : PagedListAdapter<Int, CalendarAdapter.CalendarViewHolder> {

    companion object {
        private val mDiffCallback: ItemCallback<Int> =
            object : ItemCallback<Int>() {

                override fun areItemsTheSame(oldItem: Int, newItem: Int): Boolean {
                    return false
                }

                override fun areContentsTheSame(oldItem: Int, newItem: Int): Boolean {
                    return false
                }
            }
    }

    constructor() : super(mDiffCallback)

    @NonNull
    override fun onCreateViewHolder(
        @NonNull parent: ViewGroup,
        viewType: Int
    ): CalendarViewHolder {
        val itemView: View = LayoutInflater.from(parent.context)
            .inflate(R.layout.simple_list_item_1, parent, false)
        // 只显示6行
        val parentHeight = parent.height
        val lp: ViewGroup.LayoutParams = itemView.layoutParams
        lp.height = parentHeight / 6
        itemView.layoutParams = lp
        return CalendarViewHolder(itemView)
    }

    override fun onBindViewHolder(@NonNull holder: CalendarViewHolder, position: Int) {
        holder.item.text = String.valueOf(getItem(position))
    }

    class CalendarViewHolder(@NonNull itemView: View) :
        RecyclerView.ViewHolder(itemView) {
        val item: TextView = itemView.findViewById(R.id.text1)

    }

}